package de.au.fi.manager;

import java.util.List;

import org.ektorp.CouchDbConnector;
import org.ektorp.support.GenerateView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import de.au.fi.domain.StockIdMapping;

@Component
@Service
public class StockIdMappingManager extends
		GenericManager<StockIdMapping> {

	Logger log = LoggerFactory.getLogger(this.getClass());

	@Autowired
	public StockIdMappingManager(@Qualifier("stockDatabase") CouchDbConnector db) {
		super(db, StockIdMapping.class);
	}
	
	@GenerateView
	public StockIdMapping findByTickerYahooData(String tickerYahooData) {
		List<StockIdMapping> mappings = queryView("by_tickerYahooData", tickerYahooData);
		if(mappings==null || mappings.isEmpty())
			return null;
		return mappings.get(0);
	}

}
